# Maintainer: Jordan Irwin <antumdeluge@gmail.com>

_realname=wxsvg
_wx_basever=3.2
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}-wx${_wx_basever}"
pkgbase="mingw-w64-${_realname}"
pkgver=1.5.24
pkgrel=1
pkgdesc="A C++ library to create, manipulate and render SVG files (mingw-w64)"
arch=(any)
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32')
url="https://wxsvg.sourceforge.io/"
license=("custom:wxWindows")
provides=("${MINGW_PACKAGE_PREFIX}-${_realname}")
conflicts=("${MINGW_PACKAGE_PREFIX}-${_realname}")
replaces=("${MINGW_PACKAGE_PREFIX}-${_realname}")
depends=("${MINGW_PACKAGE_PREFIX}-wxwidgets${_wx_basever}-msw-libs"
         "${MINGW_PACKAGE_PREFIX}-cairo"
         "${MINGW_PACKAGE_PREFIX}-pango"
         "${MINGW_PACKAGE_PREFIX}-expat"
         "${MINGW_PACKAGE_PREFIX}-libexif"
         "${MINGW_PACKAGE_PREFIX}-ffmpeg")
makedepends=("${MINGW_PACKAGE_PREFIX}-autotools"
             "${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-wxwidgets${_wx_basever}-msw")
source=("https://downloads.sourceforge.net/project/wxsvg/wxsvg/${pkgver}/wxsvg-${pkgver}.tar.bz2"
        "gcc11-fix.patch")
sha256sums=('ae473291f8d0a5feafa06cd270c826c6bead4bceb2b9dd6fcecf2db7c25e2482'
            'ac7b984f9ce4f051858ada88284545f4373b27a0b1200fe9f646467bd6c9f3bd')
extractdir="${_realname}-${pkgver}"
builddir="build-${CARCH}"

prepare() {
  cd "${srcdir}/${extractdir}"

  # mediadec_ffmpeg.h has a "using namespace std" conflicting with system headers.
  # ideally that would be moved to the cpp files, but the diff is too large
  patch -p1 -i "${srcdir}"/gcc11-fix.patch

  # autoreconf to get updated libtool files with clang support
  autoreconf -fiv
}

build() {
  [[ -d "${srcdir}/${builddir}" ]] && rm -rf "${srcdir}/${builddir}"
  mkdir -p "${srcdir}/${builddir}" && cd "${srcdir}/${builddir}"

  ../${extractdir}/configure \
      --prefix=${MINGW_PREFIX} \
      --host=${MINGW_CHOST} \
      --target=${MINGW_CHOST} \
      --build=${MINGW_CHOST} \
      --with-wx-config=${MINGW_PREFIX}/bin/wx-config-${_wx_basever} \
      --enable-shared \
      --enable-static
  make
}

check() {
  cd "${srcdir}/${builddir}"
  make -k check
}

package() {
  cd "${srcdir}/${builddir}"
  make install DESTDIR="${pkgdir}"

  # license
  install -Dm644 "${srcdir}/${extractdir}/COPYING" "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/COPYING"
}
